#!/bin/bash

set -e

[[ ! -d "certs" ]] && echo "not find certs" && exit 0
cd certs
[[  -z "$USER" || -z "$PASSWD" ]] && echo  "required  config files missing" && exit 0

while true ; do 
    [[ -z "$(ps -aux | grep openvpn |grep -v grep)" ]] && echo `date "+%Y-%m-%d %H:%M:%S" `  重新拉起vpn进程 && openvpn --daemon --config config.ovpn  --auth-user-pass <(echo -e "$USER\n$PASSWD") && iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
    sleep 150 
done